<?php

namespace App\Jobs;

use App\Service\Sms\SMSInterface;
use App\Tool\NoticeType;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class OrderNotice implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $type;

    private $param;

    private $phone;

    /**
     * Create a new job instance.
     *
     * @param $type
     * @param $param
     * @param string $phone
     */
    public function __construct($type, $param,$phone='')
    {
        //

        $this->type = $type;

        $this->param = $param;


        $this->phone=$phone;


    }

    /**
     * Execute the job.
     *
     * @param SMSInterface $sms
     * @return void
     */
    public function handle(SMSInterface $sms)
    {
        //

        switch ($this->type) {

            //订单已支付通知模板
            case NoticeType::order_is_pay_notice:


                $sms->sendByTemplate(\Cache::get('order_setting:phone_list'),
                    \Cache::get('order_setting:sms_sign_name'),
                    \Cache::get('order_setting:order_is_pay_notice'),
                    $this->param
                );

                break;

            //订单完成通知模板
            case NoticeType::order_finished_notice:

                if(!$this->phone) return;

                $sms->sendByTemplate($this->phone,
                    \Cache::get('order_setting:sms_sign_name'),
                    \Cache::get('order_setting:order_finished_notice'),
                    $this->param
                );

                break;

            //退款通知模板
            case NoticeType::order_refund_notice:

                $sms->sendByTemplate(\Cache::get('order_setting:phone_list'),
                    \Cache::get('order_setting:sms_sign_name'),
                    \Cache::get('order_setting:order_refund_notice'),
                    $this->param
                );


                break;

            //退款已完成通知模板
            case NoticeType::order_refund_finished_notice:

                if(!$this->phone) return;

                $sms->sendByTemplate($this->phone,
                    \Cache::get('order_setting:sms_sign_name'),
                    \Cache::get('order_setting:order_refund_finished_notice'),
                    $this->param
                );


                break;

        }

    }
}
